package com.handong.handserialprogram.module.others;

import android.os.Bundle;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.module.base.BackStackActivity;
import com.handong.handserialprogram.module.setting.AppFragment;
import com.handong.handserialprogram.module.setting.SupportFragment;
import com.handong.handserialprogram.utils.AppUtil;
import com.handong.handserialprogram.utils.LockUtil;
import com.handong.handserialprogram.utils.SPUtil;

public class OtherActivity extends BackStackActivity {

    private boolean mIsFirstBoot = false;
    private boolean mIsBack = false;

    public static final int INDEX_USER_HELPER = 1;
    public static final int INDEX_DEVICE_INFO = 2;
    public static final int INDEX_TECH_SUPP = 3;
    public static final int INDEX_CONFIG_SERVER = 4;

    @Override
    protected int getContentViewID() {
        return R.layout.activity_other;
    }

    @Override
    protected void initViewDataRes() {
        Bundle bundle = getIntent().getExtras();
        int index = bundle.getInt(SPUtil.NAV_INDEX);
        switch (index) {
            case INDEX_USER_HELPER:
                addFirstFragment(HelpFragment.newInstance(), R.id.activity_other);
                break;

            case INDEX_DEVICE_INFO:
                addFirstFragment(AppFragment.newInstance(), R.id.activity_other);
                break;

            case INDEX_CONFIG_SERVER:
                mIsFirstBoot = bundle.getBoolean(SPUtil.FIRST_BOOT, false);
                addFirstFragment(SetIPAddressFragment.newInstance(mIsFirstBoot), R.id.activity_other);
                break;
            case INDEX_TECH_SUPP:
                addFirstFragment(SupportFragment.newInstance(), R.id.activity_other);
                break;
        }
    }

    @Override
    public void onBackPressed() {
        mIsBack = true;
        super.onBackPressed();
    }

    @Override
    public void finish() {
        AppUtil.hideSoftInput(getApplicationContext(), getWindow());
        super.finish();
        if (mIsFirstBoot && mIsBack) {
            //overridePendingTransition(R.anim.anim_no, R.anim.push_right_out);
            LockUtil.releaseLockHome(getApplicationContext());
            LockUtil.releaseMenuLock(getApplicationContext());
            LockUtil.releaseStatusBarLock(getApplicationContext());
        } else if (mIsFirstBoot && !mIsBack) {
            overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        } else {
            overridePendingTransition(R.anim.anim_no, R.anim.push_right_out);
        }
    }
}
